<template>
    <div class="auditor-box">
        <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多数据"
            :immediate-check="false"
            @load="onLoad"
            >
            <showTmp 
                v-for="auditor in auditorList"
                :isRight="true"
                :key="auditor.id" 
                :dataList="auditor"
                :text="'处理订单'"
                :describe="true"
                @onTitle="getOrderDetail(auditor.id)"
                @onSlider="receipt(auditor.id, auditor.status)"
                style="margin-bottom: 5px">
            </showTmp>
        </van-list>


        <!-- 弹出框 -->
        <van-dialog
            v-model="isShowDialog"
            title="标题"
            show-cancel-button
            :cancel-button-text="'退回'"
            @confirm="confirm"
            @cancel="confirm"
            >
            <div style="margin: 10px 0">
                <van-cell-group>
                    <van-field
                        v-model="message"
                        required
                        rows="2"
                        autosize
                        label="审核意见"
                        type="textarea"
                        maxlength="50"
                        placeholder="请输入审核意见"
                        show-word-limit
                    />
                </van-cell-group>
            </div>
         </van-dialog>
    </div>
</template>

<script>
import publicNum from '~/components/_publicNum'
import showTmp from '~/components/_orderShowTmp'

export default {
    data() {
        return {
            auditorList: [],
            isShowDialog: false,
            message: '',
            loading: false,
            finished: false,
            path: 1
        }
    },
    created() {
        if(this.$store.state.user && this.$store.state.user.role_id){
            this.roleId = this.$store.state.user.role_id
            if(this.roleId === 2) {
                // 默认跳转页面
                this.$router.replace('/admin/order/pendingDisposal')
            }else if (this.roleId === 3) {
                this.$router.replace('/admin/auditor')
            }
        }
        this.getSAuditorList()
    },
    //缓存也会走的钩子
    deactivated(){
        this.$destroy(true);//销毁组件
    },
    methods: {
        // 获取order信息
        getSAuditorList() {
            this.$axios.get('/api/order', { params: {
                status: '案件内审中'
            }}).then(res => {
                if(res.status === 200) {
                    this.$store.commit('getOrderDetailList', res.data.data)
                    if(res.data.page.total <= 15) {
                        this.finished = true
                    }
                    this.auditorList = res.data.data
                }else{
                   that.$toast('请求错误');
                }
            })
        },
        getOrderDetail(id) {
            this.$axios.get(`/api/order/${id}`).then(res => {
                if(res.status === 200) {
                    this.$store.commit('getOrderDetailList', res.data.data)
                    this.$router.push(`/admin/auditor/detail/${id}`)
                }else{
                    that.$toast('请求错误');
                }
            })
        },
        receipt() {
            this.isShowDialog = true
        },
        confirm(flag) {
            let pass = ''
            if(flag){
                pass = 'yes'
            }else{
                pass = 'no'
            }
            this.$axios.get(`/api/order/${orderId}/audit/${auditId}`, { params: {
                auditor: orderId,
                order: auditId,
                pass: pass,
                review: "1"
            } })
        },
        onLoad() {
            setTimeout(() => {
                this.$axios.get('/api/order', { params: {
                    status: '案件内审中',
                    page: this.page + 1
                }}).then(res => {
                    if(res.data.data.length > 0) {
                        this.page++
                        this.auditorList.push(...res.data.data)
                        this.loading = false
                    }else{
                        this.loading = false
                        this.finished = true
                    }
                })
            }, 500);
        }
    },
    components: {
        publicNum,
        showTmp
    }
}
</script>

<style lang="less" scoped>
    .auditor{
        height: 100%;
        overflow: hidden;
        background-color: #eee;

        .van-swipe-cell{
            margin-bottom: 10px;
        }
    }
</style>